/**
 * Created by dale on 2017/8/2.
 */
var attendList=$('#attendList'),
    startDom    = $('#List_Search_StartTime'),
    endDom      = $('#List_Search_EndTime');
$(document).ready(function (){
    $('.xh-datagrid-toolbar').parseToolbar();

    startDom.datebox();
    endDom.datebox();

    startDom.datebox('setValue',getNowMonth());
    endDom.datebox('setValue', GetDateStr(0));

    attendList.initDataGrid(moduleUrl + 'staff/getAttend',{queryParams:getParams()})
        .setSelectThenEnable();

    xhTool.bindDocKeyDown($('#bt_list_search'));

    $('#bt_list_search').click(function () {
        var params = getParams();
        attendList.addDataGridParams(params);
    });

    DataGrid.onDblClickRow=function (rowIndex, rowData) {
        var startTime   = startDom.getElementValue(),
            endTime     = endDom.getElementValue();
        window.top.xhTop.showModal({
            title: '个人考勤',
            content: '<iframe src="'+moduleUrl+'staff/attendDetail?sStaffName='+escape(rowData['sStaffName'])+'&startTime='+startTime+'&endTime='+endTime+'"  style="width: 100%;;border-style: none;padding: 0px;height: 500px;"  scrolling="yes"   ></iframe>',
            size:'lg'
        });
    }

    $('#bt_list_importRec').click(function () {
        window.top.xhTop.showModal({
            title: '导入考勤信息',
            content: '<iframe src="'+moduleUrl+'staff/importAttend"  style="width: 100%;;border-style: none;padding: 0px;"  scrolling="yes"   ></iframe>',
            button:'提交',
            backClose: false
        });
    });


});

function getNowMonth() {
    var dd = new Date();
    dd.setDate(dd.getDate());//获取AddDayCount天后的日期
    var y = dd.getFullYear();
    var m = dd.getMonth()+1;//获取当前月份的日期
    return y+"-"+m+"-"+01;
}
function GetDateStr(AddDayCount) {
    var dd = new Date();
    dd.setDate(dd.getDate()+AddDayCount);//获取AddDayCount天后的日期
    var y = dd.getFullYear();
    var m = dd.getMonth()+1;//获取当前月份的日期
    var d = dd.getDate();
    return y+"-"+m+"-"+d;
}

function getParams() {
    var startTime   = startDom.getElementValue(),
        endTime     = endDom.getElementValue(),
        key         = xhExtra.getValue($('#list_search'));
    return {startTime:startTime,endTime:endTime,key:key}
}